<template>
    <div>
        <!-- 搜索 -->
        <el-form :inline="true" ref="params" size="small" :model="params" class="demo-form-inline">
            <el-form-item label="反馈建议类型">
                <el-select v-model="params.categoryName" placeholder="请选择">
                    <el-option label="其他" value="0"></el-option>
                    <el-option label="举报" value="1"></el-option>
                    <el-option label="功能调整" value="2"></el-option>
                    <el-option label="异常报告" value="3"></el-option>
                    <el-option label="界面布局" value="4"></el-option>
                    <el-option label="操作问题" value="5"></el-option>
                </el-select>
            </el-form-item>
            <!-- <el-form-item label="创建人">
                    <el-input v-model="params.createName" placeholder=""></el-input>
                </el-form-item> -->
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="onReset">重置</el-button>
                <el-button size="small" @click="batchDelete()" plain type="danger">批量删除</el-button>
                <!-- <el-button type="primary" icon="el-icon-plus" @click="handleAdd('add')">新增建议</el-button> -->
            </el-form-item>
        </el-form>
        <el-table :row-key="getKey" :data="tableData" style="width: 100%" :header-cell-style="{ background: '#f0f2f5' }" ref="tableRef"
            @selection-change="changeSelect">
            <el-table-column type="selection" width="55" reserve-selection >
            </el-table-column>
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column prop="categoryName" label="反馈建议类型"  width="170">
                <template slot-scope="scope">
                    <span v-if="scope.row.categoryName === '0'">其他</span>
                    <span v-if="scope.row.categoryName === '1'">举报</span>
                    <span v-if="scope.row.categoryName === '2'">功能调整</span>
                    <span v-if="scope.row.categoryName === '3'">异常报告</span>
                    <span v-if="scope.row.categoryName === '4'">界面布局</span>
                    <span v-if="scope.row.categoryName === '5'">操作问题</span>
                </template>
            </el-table-column>
            <el-table-column prop="content" label="内容" width="300" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="phone" label="手机号"  width="190">
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间"  width="170">
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="140">
                <template slot-scope="scope">
                    <el-button @click="handleDetail(scope.row.id)" type="text" size="small">查看详情</el-button>
                    <!-- <el-button @click="handleEdit('edit', scope.row)" type="text" size="small">修改</el-button> -->
                    <el-button @click="hanldeDelete(scope.row.id)" type="text" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="poolPage">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="params.page" :page-sizes="[10, 20, 30]" :page-size="params.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
        <RoomDialog @getTrain="getTrain" ref="formContent" />
        <!-- 查看详情 -->
        <FeedbackXqDetail ref="formContent" />
    </div>
</template>
<script>
import { feedbackList, feedbackDelete } from "@/request/api/feedback"
import RoomDialog from "./feedbackDialog.vue"
import FeedbackXqDetail from "./feedbackXqDetail.vue"
export default {
    components: {
        RoomDialog,
        FeedbackXqDetail
    },
    data() {
        return {
            multipleSelection: [],//批量选择

            tableData: [],
            params: {
                page: 1,
                pageSize: 10,
                // name: '',//连接名称
                // id:"",
                // params: {},
                // createBy: "",//创建者id
                // createTime: "",//创建时间
                // updateTime: "",//发表时间
                // createName: "",//创建人
                categoryName: "",//分类名称
                // content: "",//内容
                // phone: "",//手机号
                // userId: ""//用户名
            },
            total: 0
        }
    },
    created() {
        this.getTrain()
    },
    methods: {
        // 获取列表
        getTrain() {
            feedbackList(this.params, {}).then(res => {
                if (res.data.code === 200) {
                    this.tableData = res.data.result.items
                    this.total = res.data.result.total
                }
            })
        },
        // 查看详情
        handleDetail(info){
            this.$refs.formContent.open(info)
        },
        // 搜索
        onSubmit() {
            this.params.page = 1;
            this.getTrain();
        },
        // 重置
        onReset() {
            let params = {
                page: 1,
                pageSize: 10,
                // name: '',//连接名称
                categoryName: "",//分类名称

            }
            this.params = params
            this.getTrain();
        },
        handleSizeChange(val) {
            this.params.pageSize = val;
            this.params.page = 1;
            this.getTrain();
        },

        handleCurrentChange(val) {
            this.params.page = val;
            this.getTrain();
        },
        // 新增链接
        handleAdd(type, data) {
            this.$refs.formContent.open(type, data)
        },
        // 修改
        handleEdit(type, data) {
            this.$refs.formContent.open(type, data)
        },
        // 删除
        hanldeDelete(id) {
            this.$confirm("确定删除该条信息吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
               
                feedbackDelete(id).then((res) => {
                    if (res.data.code === 200) {
                        this.$message({
                            message: res.data.message,
                            type: "success",
                        });
                        this.getTrain()
                        this.$refs.tableRef.clearSelection();
                        
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            })
        },
          // 选择左侧复选框
          changeSelect(val) {
            this.multipleSelection = val;
        },
        getKey(row) {
            return row.id;
        },
        // 批量删除
        batchDelete() {
            if (this.multipleSelection.length === 0) {
                this.$message({
                    message: '请选择数据！',
                    type: 'warning'
                });
                return false;
            }
            // this.$confirm("确定删除吗?", "提示", {
            //     confirmButtonText: "确定",
            //     cancelButtonText: "取消",
            //     type: "warning",
            // }).then(() => {
                var ids = this.multipleSelection.map(item => item.id)
                this.hanldeDelete(ids)
            // })
        },
    }
}
</script>
<style lang="less" scoped>
.poolPage {
    margin-top: 15px;
    text-align: right;
}
</style>

